package org.chnxi.study.messagequeue.rockermq.producer;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * 发送单向消息，生产者主需要投递，不关心后续的处理
 */
public class OnewayProducer {
    public static void main(String[] args) throws RemotingException, MQClientException, InterruptedException {
        //使用默认提供的Producer
        DefaultMQProducer producer = new DefaultMQProducer();
        //设置NameServer地址
        producer.setNamesrvAddr("192.168.50.227:9876;192.168.50.227:9877");
        //启动Producer
        producer.start();

        //循环10次模拟消息发送
        for (int i=0; i<10; i++){
            //组装消息对象，设置topic、tag、msgCont，并获取发送结果
            Message msg = new Message("topicName" , "Tag" , (i+"_MessageContent").getBytes());
            producer.sendOneway(msg);
            System.out.println("单向消息发送成功："+msg.toString());
        }
    }
}
